{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "import pandas as pd\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.rcParams[\"font.sans-serif\"] = [\"STHeiti\"]\n",
    "penguins = pd.read_csv(\"data/penguins.csv\")\n",
    "penguins.dropna(inplace=True)\n",
    "penguins.info()\n",
    "penguins.head()"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "# 直方图\n",
    "sns.histplot(data=penguins, x=\"species\")"
   ],
   "id": "d07ed63accc8f666",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#核密度估计图\n",
    "'''核密度估计图（KDE，Kernel Density Estimate Plot）是一种用于显示数据分布的统计图表，它通过平滑直方图的方法来估计数据的概率密度函数，使得分布图看起来更加连续和平滑。核密度估计是一种非参数方法，用于估计随机变量的概率密度函数。其基本思想是，将每个数据点视为一个“核”（通常是高斯分布），然后将这些核的贡献相加以形成平滑的密度曲线。'''\n",
    "#绘制喙长度的核密度估计图\n",
    "sns.kdeplot(data=penguins, x=\"bill_length_mm\")"
   ],
   "id": "47138ab86d66c31",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": "sns.histplot(data=penguins, x=\"bill_length_mm\", kde=True)",
   "id": "3269b1c95234b514",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "'''计数图\n",
    "计数图用于绘制分类变量的计数分布图，显示每个类别在数据集中出现的次数，是分析分类数据非常直观的工具，可以快速了解类别的分布情况。'''\n",
    "#绘制不同岛屿企鹅数量的计数图\n",
    "sns.countplot(data=penguins, x=\"island\")"
   ],
   "id": "b3af2eabeb290eea",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#散点图\n",
    "#绘制横轴为体重，纵轴为脚蹼长度的散点图。可通过hue参数设置不同组别进行对比\n",
    "sns.scatterplot(data=penguins, x=\"body_mass_g\", y=\"flipper_length_mm\", hue=\"sex\")"
   ],
   "id": "64a3196cff49fd16",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#蜂窝图\n",
    "#通过jointplot()函数，设置kind=\"hex\"来绘制蜂窝图。\n",
    "sns.jointplot(data=penguins, x=\"body_mass_g\", y=\"flipper_length_mm\", kind=\"hex\")"
   ],
   "id": "960e054b6c5040c3",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#二维核密度估计图\n",
    "#通过kdeplot()函数，同时设置x参数和y参数来绘制二维核密度估计图。\n",
    "sns.kdeplot(data=penguins, x=\"body_mass_g\", y=\"flipper_length_mm\")"
   ],
   "id": "cea56ee6b7b71254",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#通过fill=True设置为填充，通过cbar=True设置显示颜色示意条。\n",
    "sns.kdeplot(data=penguins, x=\"body_mass_g\", y=\"flipper_length_mm\", fill=True, cbar=True)"
   ],
   "id": "f196e5cacc4edba1",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#条形图\n",
    "sns.barplot(data=penguins, x=\"species\", y=\"bill_length_mm\", estimator=\"mean\", errorbar=None)"
   ],
   "id": "7a8907bdc5a8befd",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#箱线图\n",
    "sns.boxplot(data=penguins, x=\"species\", y=\"bill_length_mm\")"
   ],
   "id": "65d0020998563079",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#小提琴图\n",
    "'''小提琴图（Violin Plot） 是一种结合了箱线图和核密度估计图（KDE）的可视化图表，用于展示数据的分布情况、集中趋势、散布情况以及异常值。小提琴图不仅可以显示数据的基本统计量（如中位数和四分位数），还可以展示数据的概率密度，提供比箱线图更丰富的信息。'''\n",
    "sns.violinplot(data=penguins, x=\"species\", y=\"bill_length_mm\")"
   ],
   "id": "e826fc341ccaab99",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "#成对关系图\n",
    "'''成对关系图是一种用于显示多个变量之间关系的可视化工具。它可以展示各个变量之间的成对关系，并且通过不同的图表形式帮助我们理解数据中各个变量之间的相互作用。\n",
    "对角线上的图通常显示每个变量的分布（如直方图或核密度估计图），帮助观察每个变量的单变量特性。其他位置展示所有变量的两两关系，用散点图表示。'''\n",
    "sns.pairplot(data=penguins, hue=\"species\")"
   ],
   "id": "415b0179fc2e8249",
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
